\documentclass[a4paper]{article}
\usepackage[affil-it]{authblk}
\usepackage[backend=bibtex,style=numeric]{biblatex}

\usepackage{geometry}
\usepackage{amsmath}
\geometry{margin=1.5cm, vmargin={0pt,1cm}}
\setlength{\topmargin}{-1cm}
\setlength{\paperheight}{29.7cm}
\setlength{\textheight}{25.3cm}

\addbibresource{citation.bib}

\begin{document}
% =================================================
\title{Numerical Analysis homework \# 1}

\author{wangjie 3220100105
  \thanks{Electronic address: \texttt{2645443470@qq.com}}}
\affil{(math), Zhejiang University }


\date{Due time: \today}

\maketitle

\begin{abstract}
    Programming homework chapter1    
\end{abstract}





% ============================================
\section*{Programming Homework}

Complete programming assignment 1.8.2 on page 8 of the lecture notes. The assignment 
requirements and specifications can be found in the content posted by the teaching assistant in the course group 
\cite{wangheyu2024}.

\subsection*{Question A}  
\textbf{Answer:}  
The code is based on the template provided by the teaching assistant. In the \texttt{function.hpp} file, the derivative is estimated using the finite difference method. Choose a sufficiently small step size \( h \) such that the derivative is calculated as 

\[
\frac{f(x+h) - f(x-h)}{2h}.
\]

The code includes a base class, \texttt{EquationSolver}, which defines a common interface for different numerical methods. Three derived classes—the Bisection Method, Newton Method, and Secant Method—each implement a specific algorithm for finding roots of a function.

The Bisection Method narrows down an interval where the function changes signs until it finds a root. The Newton Method starts from an initial guess and uses the function's derivative to iteratively improve the estimate. The Secant Method uses two initial guesses to approximate the derivative, updating its estimate accordingly.

Error handling is included to manage invalid intervals and maximum iterations, ensuring robustness.

\subsection*{Question B}  
\textbf{Answer:} 

Output:  
\begin{enumerate}
    \item Solving \( x^{-1} - \tan x \) on \([0, \frac{\pi}{2}]\): 
    A root is: \( 0.860334 \)
    
    \item Solving \( x^{-1} - 2^x \) on \([0, 1]\): 
    A root is: \( 0.641186 \)
    
    \item Solving \( 2^{-x} + e^x + 2\cos(x) - 6 \) on \([1, 3]\): 
    A root is: \( 1.82938 \)
    
    \item Solving \( (x^3 + 4x^2 + 3x + 5)(2x^3 - 9x^2 + 18x - 2) \) on \([0, 4]\): 
    A root is: \( 0.117877 \)
\end{enumerate}

\subsection*{Question C}
\textbf{Answer:} 

Output: \\
Solving \( x - \tan x \) near \( 4.5 \) and \( 7.7 \):

\begin{itemize}
    \item A root is: \( 7.72525 \)
    \item A root is: \( 4.49341 \)
\end{itemize}

\subsection*{Question D}
\textbf{Answer:} 

Output: 
\begin{enumerate}
    \item Solving \( \sin\left(\frac{x}{2}\right) - 1 \) with \( x_0 = 0 \), \( x_1 = \frac{\pi}{2} \): 
    A root is: \( 3.14093 \)
    
    \item Solving \( \sin\left(\frac{x}{2}\right) - 1 \) with \( x_0 = -4\pi \), \( x_1 = -3\pi \): 
    A root is: \( -9.42478 \)
    
    \item Solving \( e^x - \tan(x) \) with \( x_0 = 0 \), \( x_1 = 1.4 \): 
    A root is: \( -6.28131 \)
    
    \item Solving \( e^x - \tan(x) \) with \( x_0 = -4.6 \), \( x_1 = -1.6 \): 
    A root is: \( -3.09641 \)
    
    \item Solving \( x^3 - 12x^2 + 3x + 1 \) with \( x_0 = 0 \), \( x_1 = -0.5 \): 
    A root is: \( -0.188685 \)
    
    \item Solving \( x^3 - 12x^2 + 3x + 1 \) with \( x_0 = 0 \), \( x_1 = 1 \): 
    A root is: \( 0.451543 \)
\end{enumerate}

Reasons: 
\begin{itemize}
    \item \textbf{Function Behavior:} The secant method relies on the approximation of the function's root. If the chosen initial points are not close enough to the actual root, the method may converge to a different root or diverge entirely.
    
    \item \textbf{Multiple Roots:} Some functions may have multiple roots. Depending on the initial guesses, the secant method may converge to different roots.
    
    \item \textbf{Non-linearity of Functions:} Non-linear functions can exhibit steep slopes or flat regions. Initial values in regions with a steep slope may lead to faster convergence compared to those in flat regions.
    
    \item \textbf{Sensitivity to Initial Points:} The secant method is sensitive to the choice of initial guesses. Small changes in these points can lead to large differences in the outcome, especially near inflection points or discontinuities.
\end{itemize}

\subsection*{Question E}
\textbf{Answer:} \\
Solve the equation 
\[
\sin\left(\frac{\pi}{2} - 1.24 - x\sqrt{1 - x^2}\right) - x = 0 \quad \text{on } [0, 1].
\]
The depth of water \( h \) is: \( 0.17 \).

\subsection*{Question F}
\textbf{Answer:} \\
Solving the equation 
\[
A \sin(x) \cos(x) + B \sin^2(x) - C \cos(x) - E \sin(x) = 0
\]
yields the following results:

\begin{enumerate}
    \item With no initial guess, \( \alpha \) is: \( 32.9722 \).
    \item With the initial guess \( x_0 = 33^\circ \), \( \alpha \) is: \( 33.1689 \).
    \item With initial guesses \( x_0 = -1000^\circ \) and \( x_1 = 80^\circ \), \( \alpha \) is: \( 32.9722 \).
    \item With initial guesses \( x_0 = -1 \times 10^6 \) degrees and \( x_1 = 80^\circ \), \( \alpha \) is: \( 32.9722 \).
    \item With initial guesses \( x_0 = -1 \times 10^{10} \) degrees and \( x_1 = 80^\circ \), \( \alpha \) is: \( -1.5658 \times 10^{10} \).
\end{enumerate}

\begin{enumerate}
    \item \textbf{Close Initial Values:} 
    If \( x_1 \) is close to \( 33^\circ \), the secant method can quickly converge to that root. This is because the slope of the function between these two points changes little, allowing the new approximation to approach the target root rapidly.
    
    \item \textbf{Gradually Distant Initial Values:} 
    As \( x_1 \) moves further away from \( 33^\circ \), the convergence speed and success rate are affected:
    \begin{itemize}
        \item \textit{Slower Convergence:} The chosen value may still converge, but it requires more iterations.
        \item \textit{Risk of Converging to Other Roots:} If too far away, the algorithm may converge to roots of the function other than \( 33^\circ \).
        \item \textit{Potential Failure to Converge:} In extreme cases, excessively distant initial values may lead to non-convergence or oscillations.
    \end{itemize}
\end{enumerate}

% ===============================================
\section*{ \center{\normalsize {Acknowledgement}} }
None.


\printbibliography

\end{document}